package com.asia.algorithmcode.binaryTree;

import java.util.ArrayList;
import java.util.List;

/**
 * @DESCRIPTION: 101、对称二叉树
 * @USER: wanfu
 * @DATE: 2025/5/9 星期五 11:43
 */
public class IsSymmetric {

    public static void main(String[] args) {
        TreeNode n1 = new TreeNode(1);
        TreeNode n2_1 = new TreeNode(2);
        TreeNode n2_2 = new TreeNode(2);
        TreeNode n3_1 = new TreeNode(3);
        TreeNode n3_2 = new TreeNode(3);
        TreeNode n4_1 = new TreeNode(4);
        TreeNode n4_2 = new TreeNode(4);

        n1.left = n2_1;
        n1.right = n2_2;
        n2_1.left = n3_1;
        n2_1.right = n4_1;
        n2_2.left = n4_2;
        n2_2.right = n3_2;


        System.out.println(new IsSymmetric().isSymmetric(n1));

        System.out.println(" ");
    }


    public boolean isSymmetric(TreeNode root) {
        return check(root.left, root.right);
    }

    public boolean check(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        }
        if (p == null || q == null) {
            return false;
        }
        return p.val == q.val && check(p.left, q.right) && check(p.right, q.left);
    }
}
